package com.ruoyi.file.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.minio.MinioFile;
import com.ruoyi.framework.minio.MinioService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;

@RestController
@RequestMapping("/image")
public class ImagePreviewController {
    @Autowired
    private MinioService minioService;


    @GetMapping("/url/{bucket}/{object}")
    public String getFileUrl(@PathVariable String bucket,@PathVariable String object) {
        String url = minioService.getBucketObjectUrl(bucket,object);
        return url;
    }



    @GetMapping("/preview/{bucket}/{objectName}")
    public void preview(@PathVariable("bucket")String bucket,
                          @PathVariable("objectName")String objectName, HttpServletResponse response) throws Exception {
        InputStream inputStream = minioService.getObject(bucket, objectName);
        IOUtils.copy(inputStream,response.getOutputStream());
    }


}
